#pragma once

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <ctype.h>
#include <sys/epoll.h>
#include <pthread.h>
#include <signal.h>
#include <errno.h>
#include "err_str.h"
#include <malloc.h>

#include<iostream>
#include<map>
#include<list>


//边界值
#define _DEF_SIZE           45
#define _DEF_BUFFERSIZE     1000
#define _DEF_PORT           8088
#define _DEF_SERVERIP       "0.0.0.0"
#define _DEF_LISTEN         128
#define _DEF_EPOLLSIZE      4096
#define _DEF_IPSIZE         16
#define _DEF_COUNT          10
#define _DEF_TIMEOUT        10
#define _DEF_SQLIEN         400
#define TRUE                true
#define FALSE               false



/*-------------数据库信息-----------------*/
#define _DEF_DB_NAME    "huiyi"
#define _DEF_DB_IP      "localhost"
#define _DEF_DB_USER    "root"
#define _DEF_DB_PWD     "123"
/*--------------------------------------*/
#define _MAX_PATH           (260)
#define _DEF_BUFFER         (4096)
#define _DEF_CONTENT_SIZE	(1024)
#define _MAX_SIZE           (60)

//自定义协议   先写协议头 再写协议结构
//登录 注册 获取好友信息 添加好友 聊天 发文件 下线请求
#define _DEF_PACK_BASE	(10000)
#define _DEF_PACK_COUNT (100)

//注册
#define _DEF_PACK_REGISTER_RQ	(_DEF_PACK_BASE + 0 )
#define _DEF_PACK_REGISTER_RS	(_DEF_PACK_BASE + 1 )
//登录
#define _DEF_PACK_LOGIN_RQ	(_DEF_PACK_BASE + 2 )
#define _DEF_PACK_LOGIN_RS	(_DEF_PACK_BASE + 3 )
//创建房间
#define _DEF_PACK_CREATEROOM_RQ (_DEF_PACK_BASE+4)
#define _DEF_PACK_CREATEROOM_RS (_DEF_PACK_BASE+5)
//加入房间
#define _DEF_PACK_JOINROOM_RQ   (_DEF_PACK_BASE+6)
#define _DEF_PACK_JOINROOM_RS   (_DEF_PACK_BASE+7)
//房间成员加入请求
#define _DEF_PACK_ROOM_MEMBER   (_DEF_PACK_BASE+8)
//房间成员离开房间
#define _DEF_PACK_LEAVEROOM_RQ   (_DEF_PACK_BASE+9)
//房间成员离开房间回复
#define _DEF_PACK_LEAVEROOM_RS   (_DEF_PACK_BASE+10)
//音频数据
#define _DEF_PACK_AUDIO_FRAME   (_DEF_PACK_BASE+11)
//视频数据
#define _DEF_PACK_VIDEO_FRAME   (_DEF_PACK_BASE+12)
//音频注册
#define _DEF_PACK_AUDIO_REG      (_DEF_PACK_BASE+13)
//视频注册
#define _DEF_PACK_VIDEO_REG      (_DEF_PACK_BASE+14)

//返回的结果
//注册请求的结果
#define tel_is_exist		(0)
#define register_success	(1)
#define user_is_exist       (2)
#define name_is_exist       (3)
//登录请求的结果
#define user_not_exist		(0)
#define password_error		(1)
#define login_success		(2)


typedef int PackType;

//协议结构
//注册
typedef struct STRU_REGISTER_RQ
{
    STRU_REGISTER_RQ():type(_DEF_PACK_REGISTER_RQ)
    {
        memset( m_tel  , 0, sizeof(m_tel));
        memset( m_name  , 0, sizeof(m_name));
        memset( m_password , 0, sizeof(m_password) );
    }
    //需要手机号码 , 密码, 昵称
    PackType type;
    char m_tel[_MAX_SIZE];
    char m_name[_MAX_SIZE];
    char m_password[_MAX_SIZE];

}STRU_REGISTER_RQ;

typedef struct STRU_REGISTER_RS
{
    //回复结果
    STRU_REGISTER_RS(): m_type(_DEF_PACK_REGISTER_RS) , m_result(register_success)
    {
    }
    PackType m_type;
    int m_result;

}STRU_REGISTER_RS;

//登录
typedef struct STRU_LOGIN_RQ
{
    //登录需要: 手机号 密码
    STRU_LOGIN_RQ():m_ntype(_DEF_PACK_LOGIN_RQ)
    {
        memset( m_tel , 0, sizeof(m_tel) );
        memset( m_password , 0, sizeof(m_password) );
    }
    PackType m_ntype;
    char m_tel[_MAX_SIZE];
    char m_password[_MAX_SIZE];

}STRU_LOGIN_RQ;

typedef struct STRU_LOGIN_RS
{
    // 需要 结果 , 用户的id
    STRU_LOGIN_RS(): m_type(_DEF_PACK_LOGIN_RS) , m_result(login_success),m_userid(0)
    {
        memset(m_name,0,sizeof(m_name));
    }
    PackType m_type;
    int m_userid;
    int m_result;
    char m_name[_MAX_SIZE];

}STRU_LOGIN_RS;

//创建房间请求
struct STRU_CREATEROOM_RQ
{
    PackType m_ntype;
    int m_userid;

    STRU_CREATEROOM_RQ()
    {
        m_ntype = _DEF_PACK_CREATEROOM_RQ;
        m_userid = 0;
    }
};

//创建房间回复
struct STRU_CREATEROOM_RS
{
    PackType m_ntype;
    int m_roomid;
    int m_result;

    STRU_CREATEROOM_RS()
    {
        m_ntype = _DEF_PACK_CREATEROOM_RS;
        m_roomid = 0;
        m_result = 0;
    }
};

//加入房间请求
struct STRU_JOINROOM_RQ
{
    PackType m_ntype;
    int m_userid;
    int m_roomid;

    STRU_JOINROOM_RQ()
    {
        m_ntype = _DEF_PACK_JOINROOM_RQ;
        m_userid = 0;
        m_roomid = 0;
    }
};

//加入房间回复
struct STRU_JOINROOM_RS
{
    PackType m_ntype;
    int m_roomid;
    int m_result;

    STRU_JOINROOM_RS()
    {
        m_ntype = _DEF_PACK_JOINROOM_RS;
        m_roomid = 0;
        m_result = 0;
    }
};

//房间成员请求
struct STRU_ROOM_MEMBER_RQ
{
    PackType m_ntype;
    int m_userid;
    char szUserName[_MAX_SIZE];

    STRU_ROOM_MEMBER_RQ()
    {
        m_ntype = _DEF_PACK_ROOM_MEMBER;
        m_userid = 0;
        memset(szUserName,0,_MAX_SIZE);
    }
};

//离开房间请求
struct STRU_LEAVEROOM_RQ
{
    PackType m_ntype;
    int m_userid;
    int m_roomid;
    char szUserName[_MAX_SIZE];

    STRU_LEAVEROOM_RQ()
    {
        m_ntype = _DEF_PACK_LEAVEROOM_RQ;
        m_userid = 0;
        m_roomid = 0;
        memset(szUserName,0,_MAX_SIZE);
    }
};

//注册音频
struct STRU_AUDIO_REG
{
    PackType m_nType;
    int m_userid;

    STRU_AUDIO_REG():m_nType(_DEF_PACK_AUDIO_REG)
    {
        m_userid = 0;
    }
};

//注册视频
struct STRU_VIDEO_REG
{
    PackType m_nType;
    int m_userid;

    STRU_VIDEO_REG():m_nType(_DEF_PACK_VIDEO_REG)
    {
        m_userid = 0;
    }
};

//用户信息结构体 id->userinfo
struct UserInfo
{
    int m_sockfd = 0;
    int m_id = 0;
    int m_roomid = 0;
    char m_username[_MAX_SIZE];

    int m_videofd;
    int m_audiofd;

    UserInfo()
    {
        m_sockfd = 0;
        m_id = 0;
        m_roomid = 0;
        memset(m_username,0,_MAX_SIZE);
        m_videofd = 0;
        m_audiofd = 0;
    }
};













